package com.threefish.modules.sys.dao.impl;

import com.threefish.common.dao.impl.BaseDaoImpl;
import com.threefish.modules.sys.dao.UserAccountDao;
import com.threefish.modules.sys.entity.organize.UserAccount;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黄川 huchuc@vip.qq.com
 * @date: 2018/9/7
 */
@Service
public class UserAccountDaoImpl extends BaseDaoImpl<UserAccount> implements UserAccountDao {

    public UserAccountDaoImpl(Dao dao) {
        super(dao);
    }

    /**
     * 查询用户的所有权限
     *
     * @param userId 用户ID
     */
    @Override
    public List<String> queryAllPerms(String userId) {
        return new ArrayList<>();
    }

    /**
     * 查询用户的所有菜单ID
     *
     * @param userId
     */
    @Override
    public List<String> queryAllMenuId(String userId) {
        return null;
    }

    /**
     * 必须是已审核的账号才能登陆
     *
     * @param userName
     * @return
     */
    @Override
    public UserAccount loginFind(String userName) {
        return dao.fetch(this.getEntityClass(), Cnd.where("userName", "=", userName));
    }

    /**
     * 通过userName查询账号
     *
     * @param userName
     * @return
     */
    @Override
    public UserAccount fetchByUserName(String userName) {
        return dao.fetch(this.getEntityClass(), Cnd.where("userName", "=", userName).and("review", "=", 1));
    }
}
